
package org.bridgen.lang.semantics.ast;
import java.util.*;



public abstract class AttrDecl extends Element implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public AttrDecl clone() throws CloneNotSupportedException {
        AttrDecl node = (AttrDecl)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
    // Declared in TypeCodeGen.jrag at line 718

	
	public void generateCode(String indent, StringBuffer buf) {
		
		buf.append(indent + "// " + getNodeUse().getName() + "." + getName() + "\n");
		
		// Private attribute
		buf.append(indent + "protected " + cacheVariableType() + " " + cacheVariable() + ";\n");
		buf.append(indent + "protected boolean " + hasValueVariable() + " = false;\n");
		
		// Method signature 
		buf.append(indent + "public " + cacheVariableType() + " " + getName() + "() {\n");
		buf.append(indent + INDENT + "if (!" + hasValueVariable() + ") {\n");
		buf.append(indent + INDENT + INDENT + cacheVariable() + " = " + computeMethod() + "();\n");
		buf.append(indent + INDENT + INDENT + hasValueVariable() + " = true;\n");
		buf.append(indent + INDENT + "}\n");
		buf.append(indent + INDENT + "return " + cacheVariable() + ";\n");
		buf.append(indent + "}\n");
	}

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 36

    public AttrDecl() {
        super();


    }

    // Declared in bridgit.ast at line 10


    // Declared in bridgit.ast line 36
    public AttrDecl(NodeUse p0, String p1) {
        setChild(p0, 0);
        setName(p1);
    }

    // Declared in bridgit.ast at line 15


  protected int numChildren() {
    return 1;
  }

    // Declared in bridgit.ast at line 18

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 36
    public void setNodeUse(NodeUse node) {
        setChild(node, 0);
    }

    // Declared in bridgit.ast at line 5

    public NodeUse getNodeUse() {
        return (NodeUse)getChild(0);
    }

    // Declared in bridgit.ast at line 9


    public NodeUse getNodeUseNoTransform() {
        return (NodeUse)getChildNoTransform(0);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 36
    protected String tokenString_Name;

    // Declared in bridgit.ast at line 3

    public void setName(String value) {
        tokenString_Name = value;
    }

    // Declared in bridgit.ast at line 6

    public String getName() {
        return tokenString_Name != null ? tokenString_Name : "";
    }

    // Declared in NameAnalysis.jrag at line 108
 @SuppressWarnings({"unchecked", "cast"})     public boolean isNodeAttr() {
        boolean isNodeAttr_value = isNodeAttr_compute();
        return isNodeAttr_value;
    }

    private boolean isNodeAttr_compute() {  return false;  }

    // Declared in TypeAnalysis.jrag at line 74
 @SuppressWarnings({"unchecked", "cast"})     public String returnType() {
        String returnType_value = returnType_compute();
        return returnType_value;
    }

    private String returnType_compute() {  return "";  }

    // Declared in TypeCodeGen.jrag at line 548
 @SuppressWarnings({"unchecked", "cast"})     public boolean isNodeAttrDecl() {
        boolean isNodeAttrDecl_value = isNodeAttrDecl_compute();
        return isNodeAttrDecl_value;
    }

    private boolean isNodeAttrDecl_compute() {  return false;  }

    // Declared in TypeCodeGen.jrag at line 713
 @SuppressWarnings({"unchecked", "cast"})     public String cacheVariable() {
        String cacheVariable_value = cacheVariable_compute();
        return cacheVariable_value;
    }

    private String cacheVariable_compute() {  return getName() + "_value";  }

    // Declared in TypeCodeGen.jrag at line 714
 @SuppressWarnings({"unchecked", "cast"})     public String hasValueVariable() {
        String hasValueVariable_value = hasValueVariable_compute();
        return hasValueVariable_value;
    }

    private String hasValueVariable_compute() {  return getName() + "_hasValue";  }

    // Declared in TypeCodeGen.jrag at line 715
 @SuppressWarnings({"unchecked", "cast"})     public String computeMethod() {
        String computeMethod_value = computeMethod_compute();
        return computeMethod_value;
    }

    private String computeMethod_compute() {  return getName() + "_compute";  }

    // Declared in TypeCodeGen.jrag at line 716
 @SuppressWarnings({"unchecked", "cast"})     public String cacheVariableType() {
        String cacheVariableType_value = cacheVariableType_compute();
        return cacheVariableType_value;
    }

    private String cacheVariableType_compute() {  return "Object";  }

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

    protected void collect_contributors_NodeDecl_attrDecls() {
        // Declared in TypeCodeGen.jrag at line 23
        {
            NodeDecl ref = (NodeDecl)(getNodeUse().decl());
            if(ref != null)
                ref.NodeDecl_attrDecls_contributors.add(this);
        }
        super.collect_contributors_NodeDecl_attrDecls();
    }
    protected void contributeTo_NodeDecl_NodeDecl_attrDecls(Collection collection) {
        super.contributeTo_NodeDecl_NodeDecl_attrDecls(collection);
        collection.add(this);
    }

}
